[iOS] Fix buttons crash when unmounting children#4065
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes an iOS (Fabric) crash when removing children from the Gesture Handler Clickable/button component by changing how child views are unmounted from the underlying UIControl.
Changes:
- Update
RNGestureHandlerButtonComponentViewunmount behavior to avoidUIControl’s strict index checks during child unmount.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - (void)unmountChildComponentView:(RNGHUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index | ||
| { | ||
| [_buttonView unmountChildComponentView:childComponentView index:index]; | ||
| [childComponentView removeFromSuperview]; |
There was a problem hiding this comment.
unmountChildComponentView:index: now calls removeFromSuperview on the child without verifying it’s still mounted under _buttonView. Since removeFromSuperview detaches from whatever the current superview is, this can unmount the view from a different parent if it has already been reattached elsewhere. Consider guarding on childComponentView.superview == _buttonView (or deriving the current index from _buttonView.subviews and using that), and explicitly mark index as unused to avoid unused-parameter warnings.
| [childComponentView removeFromSuperview]; | |
| (void)index; | |
| if (childComponentView.superview == _buttonView) { | |
| [childComponentView removeFromSuperview]; | |
| } |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
buttonViewisUIControl, which unlikeRCTViewComponentViewdoes strict checks for view index when unmounting children.Fixes #4062
Test plan
Tested on example from #4062